package com.aj.activity.adapter;

import java.util.HashMap;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.aj.activity.R;
import com.aj.databases.entry.Family;
import com.aj.utils.PortraitLoaderUtil;

public class MoreFamilyAdapter extends BaseAdapter {

	private List<Family> data;

	private HashMap<Integer, View> viewCache = new HashMap<Integer, View>();

	private Context context;

	public MoreFamilyAdapter(Context context, List<Family> data) {
		this.data = data;
		this.context = context;
	}

	@Override
	public int getCount() {
		return data.size();
	}

	@Override
	public Object getItem(int arg0) {
		return data.get(arg0);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	class ViewHolder {
		ImageView family_head;
		TextView name;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		convertView = viewCache.get(position);
		ViewHolder viewHolder = null;
		Family family = data.get(position);
		if (convertView == null) {
			viewHolder = new ViewHolder();
			convertView = LayoutInflater.from(context).inflate(
					R.layout.item_more_family, null);
			viewHolder.name = (TextView) convertView.findViewById(R.id.name);
			viewHolder.family_head = (ImageView) convertView
					.findViewById(R.id.family_head);
			convertView.setTag(viewHolder);
			viewCache.put(position, convertView);
			PortraitLoaderUtil.loadSrc(context, viewHolder.family_head, null,
					family.getPhoto_url(), R.drawable.nomal_photo,
					R.drawable.nomal_photo);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}
		viewHolder.name.setText(family.getCallName());

		return convertView;
	}

}
